package com.conlin.learn.io;

import com.conlin.learn.common.contant.Contant;
import com.conlin.learn.common.proxy.CommonService;

import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.nio.charset.StandardCharsets;
import java.util.Locale;

public class MemoryStreamDecorator implements CommonService {

    @Override
    public void doSomething() {
        String str = "Hello World";

        try (ByteArrayInputStream byteArrayInputStream = new ByteArrayInputStream(str.getBytes(StandardCharsets.UTF_8));
             ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream()) {

//            byte[] bytes = new byte[Contant.BYTE_LENGTH];
//            int i;
//            while ((i = byteArrayInputStream.read(bytes)) != -1) {
//                byteArrayOutputStream.write(bytes, 0, i);
//            }

            int i;
            while ((i = byteArrayInputStream.read()) != -1) {
                char a = (char)i;
                char upperCase = Character.toUpperCase(a);
                byteArrayOutputStream.write(upperCase);
            }

            System.out.println(byteArrayOutputStream.toString(StandardCharsets.UTF_8));
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
}
